format debug "--  Compiling Scene Class . . .\n" undefined undefined

Class Scene(TwoDSpace)
instance variables
	sceneMasterClock
	currentDropSpot
	myControllers
	myStage
	name
	helpVideo
	sceneAudio
	loopAudio
	players
	BOM
	Portals
	loopCB
End --Scene

method afterInit self {class Scene} #rest args #key lingo:->
(
	local myControllers := self.myControllers
	myControllers := new array
	append myControllers (new DragController space:self wholespace:true)
	append myControllers (new Movement space:self wholespace:true)
	append myControllers (new SmartBounce space:self wholespace:true)
	append myControllers (new ActuatorController space:self wholespace:true)
	self.myControllers := myControllers
	self.sceneAudio := undefined
	self.BOM := new Array
	local portals := #(@north:undefined,@south:undefined,@east:undefined,@west:undefined)
	
	local thisPortal := findSXKey(lingo, "North")
	if thisPortal <> undefined do setOne portals @North thisPortal
	
	thisPortal := findSXKey(lingo, "South")
	if thisPortal <> undefined do setOne portals @South thisPortal
	
	thisPortal := findSXKey(lingo, "East")
	if thisPortal <> undefined do setOne portals @East thisPortal
	
	thisPortal := findSXKey(lingo, "West")
	if thisPortal <> undefined do setOne portals @West thisPortal
	
	self.loopAudio := (findSXKey(lingo, "soundLooped") = "yes")
	self.portals := portals
	self.players := #()
	return self
)

method unhook self {Class Scene} ->
(
	for ctrl in self.myControllers do (
		if ctrl.enabled = true do (
			ctrl.enabled := false
		)
	)
	for element in self do (
		if (canObjectDo element unhook) do (
			unhook element
		)
	)
	local loop := self.loopCB
	if loop <> undefined do (
		cancel loop
		self.loopCB := undefined
	)
	for plyr in self.players do stop plyr
)

method hook self {Class Scene} ->
(
	for ctrl in self.myControllers do (
		if ctrl.enabled = false do (
			ctrl.enabled := true
		)
	)
	for element in self do (
		if (canObjectDo element hook) do (
--			format debug "hooking: %*\n" element @unadorned
			hook element
		)
	)
)

method showHelp self {Class Scene} ->
(
	local orb := self[1]
	if orb.size = 1 then (
		local myHelp := self.helpVideo
		if (not (isAKindOf orb SlingShotOrb)) or myHelp = undefined do
			return empty
		stop myHelp
		gotoBegin myHelp
		playprepare myHelp 1
		if orb[1] <> myHelp do
			prepend orb myHelp
		play myHelp
	) else (
		pop orb
	)
)
method setHelp self {Class Scene} helpVid->
(
	if helpVid <> undefined do (
		helpVid[1].invisibleColor := new rgbColor red:51 green:51 blue:255
		self.helpVideo := helpVid
	)
)
#(Scene,#("portals","name","myControllers","sceneAudio","players","loopAudio"),#("hook","unhook","showHelp","setHelp"))
